import math

try :    
    cmds.delete( dellist )
    dellist = []
except :
    dellist = []
    
Lfootmain = cmds.createNode( 'distanceBetween' , n = 'Lfootmain' )    
Rfootmain = cmds.createNode( 'distanceBetween' , n = 'Rfootmain' ) 
LRfoot = cmds.createNode( 'distanceBetween' , n = 'LRfoot' )
dellist.append( Lfootmain ) 
dellist.append( Rfootmain ) 
dellist.append( LRfoot )

cmds.connectAttr('main.t' ,Lfootmain+'.p1' )
cmds.connectAttr('L_foot.t' ,Lfootmain+'.p2' )
LfootmainDist = cmds.getAttr( Lfootmain+'.d' )

cmds.connectAttr('main.t' ,Rfootmain+'.p1' )
cmds.connectAttr('R_foot.t' ,Rfootmain+'.p2' )
RfootmainDist = cmds.getAttr( Rfootmain+'.d' )

cmds.connectAttr('L_foot.t' ,LRfoot+'.p1' )
cmds.connectAttr('R_foot.t' ,LRfoot+'.p2' )
LRfootDist = cmds.getAttr( LRfoot + '.d' )

class autowalk:
    def __init__( self ):
        pass
    
    def walk( self , tg ):
        pass
    
def testwalk():
    global radL
    global radR
    ct = cmds.currentTime( q=1 )
    if ct == 1 :
        cmds.setAttr('R_foot.tz' , 0)
        cmds.setAttr('R_foot.ty' , 0)
        cmds.setAttr('L_foot.tz' , 0)
        cmds.setAttr('L_foot.ty' , 0)
    mainZ = cmds.getAttr( 'main.tz' )
    mainZ1 = cmds.getAttr( 'main.tz' , t= ct-2 )
    RfootmainDist = cmds.getAttr( 'Rfootmain.d' )
    v = mainZ - mainZ1
    
    #if RfootmainDist > 3 :#or cmds.getAttr( 'R_foot.ty') != 0 :   
    if cmds.getAttr('L_foot.ty')==0:
        cmds.setAttr( 'R_foot.ty' , max( 0 , math.sin(radR) ) )
        if not v:return
        radR = (radR + math.pi/3.0) #% math.pi
        
    if cmds.getAttr('R_foot.ty') !=0:
        cmds.setAttr( 'R_foot.tz' , mainZ )        
        #cmds.move(  0,0,  mainZ,'R_foot', r=1 )        
        
    #if LfootmainDist > 3 :#or cmds.getAttr( 'L_foot.ty') != 0 :      
    if cmds.getAttr('R_foot.ty')==0:        
        cmds.setAttr( 'L_foot.ty' , max( 0 , math.sin(radL ) ) )
        if not v:return
        radL = (radL + math.pi/3.0) #% math.pi
        
    if cmds.getAttr('L_foot.ty') !=0:
        cmds.setAttr( 'L_foot.tz' , mainZ )
        
        #cmds.move(  0,0,  mainZ,'R_foot', r=1 )        
        

exp = cmds.expression( s='python("testwalk()")' , ae = 1 )
dellist.append( exp )